<?php
 

use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

class CreateExchangeTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('exchange_pair', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('交易对币本位');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('legal_id')->comment('法币id');
            $table->tinyInteger('is_trade')->comment('开启现货交易')->unsigned()->default(0);
            $table->tinyInteger('is_contract')->comment('开启合约交易')->unsigned()->default(0);
            $table->tinyInteger('is_futures')->comment('开启期权交易')->unsigned()->default(0);
            $table->integer('sort')->comment('排序')->unsigned()->default(100);
            $table->tinyInteger('status')->comment('1正常')->unsigned()->default(1);
        });
        Schema::create('exchange_pair_list', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('交易对列表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('legal_id')->comment('法币id');
            $table->bigInteger('currency_id')->comment('币种id');
            $table->tinyInteger('status')->comment('启用0否1是')->unsigned()->default(1);
            $table->tinyInteger('is_show')->comment('显示0否1是')->unsigned()->default(1);
            $table->integer('sort')->comment('排序')->unsigned()->default(100);
            $table->decimal('face_value', 11, 4)->comment('面值')->unsigned()->default(0);
            $table->decimal('fee_open', 11, 4)->comment('手续费开仓或买单')->unsigned()->default(0);
            $table->decimal('fee_close', 11, 4)->comment('手续费平仓')->unsigned()->default(0);
            $table->decimal('min_sell', 11, 4)->comment('最低卖单')->unsigned()->default(0);
            $table->decimal('max_sell', 11, 4)->comment('最高卖单')->unsigned()->default(0);
            $table->decimal('min_amount', 11, 4)->comment('最低挂单数量')->unsigned()->default(0);
            $table->decimal('max_amount', 11, 4)->comment('最高挂单数量')->unsigned()->default(0);
            $table->decimal('keep_rate', 5)->comment('保证金维持率')->unsigned()->default(0.01);
            $table->smallInteger('max_lever')->comment('最高杠杆倍数')->unsigned()->default(200);
            $table->tinyInteger('funds_interval')->comment('资金费率结算周期，小时')->unsigned()->default(1);
            $table->tinyInteger('slippage_type')->comment('类型0无1百分比2固定点')->unsigned()->default(0);
            $table->decimal('slippage_type_val', 11, 4)->comment('滑点')->unsigned()->default(0);
            $table->unique(['legal_id', 'currency_id']);
        });

        Schema::create('exchange_kline_1s', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('1秒k线');
            $table->bigIncrements('id')->comment('主键');

        });


    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('exchange_pair');
        Schema::dropIfExists('exchange_pair_list');
    }
}
